<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<script type="text/javascript">
<!--
	function readAllMessage() {
		$.get("app/message/readAll");
		messageReceiverGrid.reload();
	}
//-->
</script>

<isperp:grid url="app/message/listDetails"
	autoReloadTreeMenu="myMessageMenu" gridId="messageReceiverGrid"
	cusDialogSize="normal" showSearchbar="true" showToolbar="true"
	ondbClickRowEvent="readMessage(rowid)" actionsWidth="70"
	cusActions="messageActions(rowObject)" cusViewUrl="app/message/view">
	
	<jsp:attribute name="toolbar">
	<isperp:treeMenu id="myMessageMenu" targetGridId="messageReceiverGrid">
		<isperp:async enable="true" url="app/message/myMessageMenu"></isperp:async>
		<isperp:callback onClick="myMessageMenuTree_onNodeClick"
					onAsyncSuccess="myMessageMenuTree_onNodeClickFirst();">
		</isperp:callback>
	</isperp:treeMenu>
	<isperp:toolbar id="messageReceiverGridToolbar">
		<isperp:button id="messageReceiverGridCreate" icon="icon-plus"
					text="发送新消息"
					onclick="isperp.openDialog({windowSize:'normal',title:'发送新消息',contentUrl:'app/message/sender/sendEdit'});"></isperp:button>
	</isperp:toolbar>
	
		<button id="messageReadAll" onclick="readAllMessage()">已读所有</button>
	
	</jsp:attribute>
	<jsp:body>
	<isperp:column name="id" title="id" hidden="true"></isperp:column>
	
	<isperp:column name="readed" title="" width="35" isFormatterFun="true"
				formatter="return formatterReadedStatus(cellvalue);">
	</isperp:column>
	<isperp:column name="content" title="内容" width="380">
	</isperp:column>
	<isperp:column name="sender_name" title="发送者" width="80">
	</isperp:column>
	<isperp:column name="create_date" title="发送时间" width="110"> 
	</isperp:column>
	<isperp:column name="receiver_name" title="接收者" width="80">
	</isperp:column>
	</jsp:body>
</isperp:grid>
<script type="text/javascript">
	function messageActions(rowObject) {
		return isperp.createGridAction({
			title : '回复',
			iconCls : 'icon-change',
			onclick : "replayMessage('" + rowObject.id + "')"
		})
	};

	function replayMessage(rowid) {

		messageReceiverGrid.jqGrid.jqGrid('setCell', rowid, 'readed', "1");
		isperp.openDialog({
			title : '回复消息',
			contentUrl : "app/message/receiver/replyEdit?messageId=" + rowid
		});
	};

	function formatterReadedStatus(v) {

		if (v == "1") {

			return "<img src='img/icons/packs/fugue/24x24/mail-open.png'>";
		} else {
			return "<img src='img/icons/packs/fugue/24x24/mail.png'>";
		}

	};

	function readMessage(rowid) {
		messageReceiverGrid.jqGrid.jqGrid('setCell', rowid, 'readed', "1");
		messageReceiverGrid.view(rowid);
	}
</script>
<isperp:buttonList>

</isperp:buttonList>
